project(
    'argparse-f',
    'fortran',
    version : '1.0.0',
    license : 'MIT',
    default_options : [
        'buildtype=debugoptimized',
        'fortran_std=f2008'
    ]
)

argparse_f_src = files(
    'src/argparse-f.f90'
)

argparse_f_lib = library(
    meson.project_name(),
    sources : argparse_f_src,
    version : meson.project_version(),
    install : true,
)

argparse_f_inc = argparse_f_lib.private_dir_include()
argparse_f_dep = declare_dependency(
    link_with : argparse_f_lib,
    include_directories : argparse_f_inc,
)

test(
    'argparse_f_check',
    executable(
        'argparse_f_check',
        'test/check.f90',
        dependencies : argparse_f_dep,
    ),
)

argparse_lic = files('LICENSE')
install_data(
    argparse_lic,
    install_dir : get_option('datadir')/'licenses'/meson.project_name(),
)
if host_machine.system() == 'windows'
    symbols_file = 'lib'+meson.project_name()+'-'+meson.project_version().split('.')[0]+'.dll.symbols'
    obj_suffix = '.obj'
else
    symbols_file = 'lib'+meson.project_name()+'.so.'+meson.project_version()+'.symbols'
    obj_suffix = '.o'
endif
install_subdir(argparse_f_lib.path()+'.p',
    install_dir: 'include'/meson.project_name(),
    strip_directory: true,
    exclude_files: [
        'depscan.dd',
        meson.project_name()+'-deps.json',
        symbols_file,
        meson.project_name()+'.dat',
        'src_argparse-f.f90'+obj_suffix,
    ]
)
pkg = import('pkgconfig')
pkg.generate(
    argparse_f_lib,
    name: meson.project_name(),
    description: 'Modern Fortran command line parser, implemented with OOP.',
    version: meson.project_version(),
    subdirs: meson.project_name(),
)
